//
//  JYProgressView.swift
//  WeiBoDemo
//
//  Created by 万佳阳 on 16/8/8.
//  Copyright © 2016年 JYWan. All rights reserved.
//

import UIKit

class JYProgressView: UIView {
    // MARK:- 定义属性
    var progress : CGFloat = 0 {
        didSet {
            setNeedsDisplay()
        }
    }
    
    // MARK:- 重写drawRect
    override func drawRect(rect: CGRect) {
        super.drawRect(rect)
        
        //参数
        let arcCenter = CGPoint(x: rect.width * 0.5, y: rect.height * 0.5)
        let radius = rect.width * 0.5 - 3
        let startAngle = CGFloat(-M_PI_2)
        let endAngle = CGFloat(M_PI * 2) * progress + startAngle
        
        //创建贝赛尔曲线
        let path = UIBezierPath(arcCenter: arcCenter, radius: radius, startAngle: startAngle, endAngle: endAngle, clockwise: true)
        
        //绘制一条中心点的线
        path.addLineToPoint(arcCenter)
        path.closePath()
        
        //设置绘制的颜色
        UIColor(white: 1.0, alpha: 0.5).setFill()
        
        //开始绘制
        path.fill()
    }
 

}
